package com.autcar.training.service;

import com.autcar.training.dao.GoodsMapper;
import com.autcar.training.entity.Customer;
import com.autcar.training.entity.Goods;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.ietf.jgss.GSSContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ProjectName: training
 * @Package: com.autcar.training.service
 * @ClassName: GoodsServiceImpl
 * @Author: YHHHH
 * @Description: 商品CRUD
 * @Date: 2020/8/28 23:18
 * @Version: 1.0
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Resource
    private GoodsMapper goodsMapper;
    //查询所有商品
    @Override
    public List<Goods> findAllGoods() {
        return goodsMapper.selectList(null);
    }

    //增加所有商品
    @Override
    public int addGoods(Goods goods) {
        return goodsMapper.insert(goods);
    }

    //删除一个商品
    @Override
    public int deleteGoods(Integer id) {
        return goodsMapper.deleteById(id);
    }

    //更新商品
    @Override
    public int updateGoods(Goods goods) {
        return goodsMapper.updateById(goods);
    }

    //根据商品名字模糊查询商品
    @Override
    public List<Goods> findByName(String name) {
        return goodsMapper.selectList(new QueryWrapper<Goods>().like("name",name));
    }

    //价格区间
    @Override
    public List<Goods> findByPrice(Integer low, Integer high) {
        List<Goods> findByPrice = goodsMapper.selectList(new QueryWrapper<Goods>().between("price", low, high));
        return findByPrice;
    }
}
